package com.yz.demo.web;

import com.yz.demo.model.Repos;
import com.yz.demo.service.DemoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import retrofit2.Call;
import retrofit2.Response;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * @author shanchong
 * @date 2019-07-10
 **/
@RestController
public class DemoController {

    @Autowired
    private DemoService demoService;

    @RequestMapping(value = "/test")
    public String test(){
        final Call<List<Repos>> call = demoService.resposList("lovelyesz");
        Response<List<Repos>> execute = null;
        try {
            execute = call.execute();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return execute.body().toString();
    }

    @RequestMapping(value = "/test/1")
    public String test1(@RequestParam(value = "param") String param){
        System.out.println("param:"+param);
        final String s = "<xml><id>1</id><name>单冲</name><node_id>123</node_id></xml>";
        try {
            return URLEncoder.encode(s,"GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

}
